from fastapi import FastAPI, Body, UploadFile

import api.service.knowledgebase_item_service as knowledgebase_item_service
from api.vo.ResponseVo import ResponseVo
from api.vo.form.knowledge_item_form import KnowledgebaseItemForm
from api.vo.query.knowledgebase_item_query import KnowledgebaseItemQuery


async def list(knowledgebaseItemQuery: KnowledgebaseItemQuery):
    return knowledgebase_item_service.list(knowledgebaseItemQuery=knowledgebaseItemQuery)


async def enable(knowledgeItemForm: KnowledgebaseItemForm):
    print(knowledgeItemForm)
    return knowledgebase_item_service.enabled(idList=knowledgeItemForm.idList)


async def disabled(knowledgeItemForm: KnowledgebaseItemForm):
    return knowledgebase_item_service.disabled(idList=knowledgeItemForm.idList)


async def deletes(knowledgeItemForm: KnowledgebaseItemForm):
    return knowledgebase_item_service.deletes(idList=knowledgeItemForm.idList)


async def upload(file: UploadFile, kb_id: str):
    ret = await knowledgebase_item_service.add(file=file, kb_id=kb_id)
    return ResponseVo(data=ret)


def add_knowledgebase_item_routes(app: FastAPI):
    app.post("/knowledgebase_item/list", summary="文档列表", description="文档列表")(list)
    app.post("/knowledgebase_item/enable", summary="启用文档", description="启用文档")(enable)
    app.post("/knowledgebase_item/disabled", summary="禁用文档", description="禁用文档")(disabled)
    app.post("/knowledgebase_item/deletes", summary="删除文档", description="删除文档")(deletes)
    app.post("/knowledgebase_item/upload/{kb_id}", summary="上传文档", description="上传文档")(upload)
